package com.mobiletrain.org.motherkitch.shouye;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.lidroid.xutils.BitmapUtils;
import com.mobiletrain.org.motherkitch.R;
import com.mobiletrain.org.motherkitch.utils.ImageLoad;

import java.util.ArrayList;

/**
 * Created by Administrator on 2015/4/26.
 */
public class PostAdapter extends BaseAdapter{
    private Context context;
    private ArrayList<Post> data;

    public PostAdapter(Context context, ArrayList<Post> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        if(data!=null){
            return data.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder2 holder2 = null;
        if (convertView == null) {
            holder2 = new ViewHolder2();
            convertView = LayoutInflater.from(context).inflate(R.layout.shouye_list_item2, null);
            holder2.dated = (TextView) convertView.findViewById(R.id.shouye_item2_dated);
            holder2.title3 = (TextView) convertView.findViewById(R.id.shouye_item2_title);
            holder2.nickname = (TextView) convertView.findViewById(R.id.shouye_item2_nickname);
            holder2.avatar = (ImageView) convertView.findViewById(R.id.shouye_item2_image);
            convertView.setTag(holder2);
        } else {
            holder2 = (ViewHolder2) convertView.getTag();
        }
        Post info = data.get(position);
        holder2.dated.setText(info.getDated());
        holder2.nickname.setText(info.getNickname());
        holder2.title3.setText(info.getTitle());
        BitmapUtils bitmapUtils = ImageLoad.getBitmapUtils(context);
        bitmapUtils.display(holder2.avatar, info.getAvatar());
        return convertView;
    }
    class ViewHolder2{
        TextView dated;
        ImageView avatar;
        TextView  nickname;
        TextView  title3;
    }
}
